<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FirmBrandMessage;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FirmBrandMessageController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new FirmBrandMessage(['brand:id,name']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('type')
                 ->using([1 => '一键加盟',2 =>'咨询', 3 =>'项目认领']);
            $grid->column('brand.name','所属品牌');
            $grid->column('name');
            $grid->column('content')
                ->width(200);
            $grid->column('sex')
                 ->using([1 => '男',2 =>'女',0 =>'未知']);
            $grid->column('phone');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->disableCreateButton();
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('type')
                       ->select([1 => '一键加盟',2 =>'咨询', 3 =>'项目认领'])
                       ->width(3);
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FirmBrandMessage(), function (Show $show) {
            $show->field('id');
            $show->field('type');
            $show->field('brand_id');
            $show->field('user_id');
            $show->field('name');
            $show->field('content');
            $show->field('sex');
            $show->field('phone');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new FirmBrandMessage(), function (Form $form) {
            $form->display('id');
            $form->text('type');
            $form->text('brand_id');
            $form->text('user_id');
            $form->text('name');
            $form->text('content');
            $form->text('sex');
            $form->text('phone');
            $form->text('status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
